#include <iostream>
#include <cstdlib>

typedef unsigned int uint_t;

void complexNumber(std::string const &firstNumber, std::string &Real, std::string &Im){
    int number = 0;
    for (uint_t i = 0; i < firstNumber.length(); ++i)
    {
        if (firstNumber.at(i) != ' ')
        {
            if (firstNumber.at(i) == '+' || firstNumber.at(i) == '-')
            {
                ++number;
                if (number == 1)
                {
                    Real = firstNumber.at(i);
                }
                if (number == 2)
                {
                    Im = firstNumber.at(i);
                }
            }
            if (number == 1 && isdigit(firstNumber.at(i)))
            {
                Real += firstNumber.at(i);
            }

            if (number == 2 && isdigit(firstNumber.at(i)))
            {
                Im += firstNumber.at(i);
            }
        }
    }
}

int
main(int argc, const char* argv[])
{
    std::string firstNumber;
    std::string secondNumber;
    std::string firstReal;
    std::string firstIm;
    std::string secIm;
    std::string secReal;

    std::cout << "Enter a + bi: ";
    std::getline(std::cin, firstNumber);
    std::cout << "Enter b + di: ";
    std::getline(std::cin, secondNumber);

    complexNumber(firstNumber, firstReal, firstIm);
    complexNumber(secondNumber, secReal, secIm);

    int a = atoi(firstReal.c_str());
    int b = atoi(firstIm.c_str());
    int c = atoi(secReal.c_str());
    int d = atoi(secIm.c_str());

    std::cout << "(" << firstNumber << ") * (" << secondNumber << ") = (";
    std::cout << (a*c - b*d) << " + " << (b*c + a*d) << "i)";
}
